<template>
  <div class="new-post-form">
    <h2>发布新帖子</h2>
    <form @submit.prevent="handleSubmit">
      <div class="form-group">
        <label for="post-author">作者:</label>
        <input type="text" id="post-author" v-model="author" required />
      </div>
      <div class="form-group">
        <label for="post-title">标题:</label>
        <input type="text" id="post-title" v-model="title" required />
      </div>
      <div class="form-group">
        <label for="post-content">内容:</label>
        <textarea id="post-content" v-model="content" rows="5" required></textarea>
      </div>
      <button type="submit" class="submit-button">发布</button>
    </form>
  </div>
</template>

<script setup>
import { ref, defineEmits } from 'vue';

const author = ref('');
const title = ref('');
const content = ref('');

const emits = defineEmits(['submitPost']);

const handleSubmit = () => {
  emits('submitPost', {
    author: author.value,
    title: title.value,
    content: content.value,
  });
  author.value = '';
  title.value = '';
  content.value = '';
};
</script>

<style scoped>
.new-post-form {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.new-post-form h2 {
  color: #555;
  margin-top: 0;
  margin-bottom: 20px;
  text-align: center;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
  color: #666;
}

.form-group input[type="text"],
.form-group textarea {
  width: calc(100% - 20px);
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
}

.form-group textarea {
  resize: vertical;
}

.submit-button {
  display: block;
  width: 100%;
  padding: 10px 15px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
  transition: background-color 0.3s ease;
}

.submit-button:hover {
  background-color: #45a049;
}
</style>